<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>清除画布</title>
    <style>
        #canvas {
            display: block;
            margin: 50px auto;
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="400" height="400"></canvas>
</body>
<script>

let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');          // 得到2d的画笔

// 绘制方法一
context.fillStyle = '#b2b4b6'; 
context.beginPath();
context.moveTo(100, 100);           // 定义开始的起点             
context.lineTo(300, 100);           // 从起点到(300, 100)
context.lineTo(200, 300);           // 从起点到(200, 300)
context.closePath();            // 闭合三角形
context.stroke();
context.fill();

context.clearRect(0, 0, 400, 200);          // 清除画布

</script>
</html>